package main

import (
	"html/template"
	"net/http"
)

type Todo struct {
	Title string
	Done  bool
}
type TodoPageData struct {
	PageTitle string
	Todos     []Todo
}

func main() {
	//1 定义数据context
	data := TodoPageData{
		PageTitle: "My TODO List",
		Todos: []Todo{
			{Title: "task 1", Done: false},
			{Title: "task 2", Done: false},
			{Title: "task 3", Done: false},
		},
	}
	//2 读取并解析模板文件
	tmpl := template.Must(template.ParseFiles("layout.html"))

	http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		//3 整个data 就是context ,就是 .
		tmpl.Execute(writer, data)
	})
	http.ListenAndServe(":8989", nil)
}
